package com.rayboo.example.design.pattern.observable;

public class ForecastBoard implements Board, Observer {

    private float mCurrentPressure = Float.MAX_VALUE;
    private float mLastPressure = Float.MAX_VALUE;

    @Override
    public void display() {
        if (mCurrentPressure == Float.MAX_VALUE || mLastPressure == Float.MAX_VALUE) {
            System.out.println("无法预测");
            return;
        }

        String message;
        if (mCurrentPressure > mLastPressure) {
            message = "气压正在升高";
        } else if (mCurrentPressure == mLastPressure) {
            message = "气压平稳";
        } else {
            message = "气压正在降低";
        }
        System.out.println(message);
    }


    @Override
    public void onNotify(float temperature, float humidity, float pressure) {
        mLastPressure = mCurrentPressure;
        mCurrentPressure = pressure;
        display();
    }
}
